Skip to content

[Python] Set a Beam user agent on the boto3 S3 client - #39574

Draft
goanpeca wants to merge 1 commit into
apache:masterfrom
goanpeca:python-s3-client-user-agent
Draft

[Python] Set a Beam user agent on the boto3 S3 client#39574
goanpeca wants to merge 1 commit into
apache:masterfrom
goanpeca:python-s3-client-user-agent

Conversation

@goanpeca

Copy link
Copy Markdown

Addresses #39573

apache_beam.io.aws.clients.s3.boto3_client.Client builds its boto3 client without a botocore Config, so every S3 request Beam makes goes out with the stock boto3 user agent and carries nothing identifying the caller as Beam. The other cloud clients in the Python SDK all tag themselves already: gcsio.py sends apache-beam/<version> (GPN:Beam), bigquery_tools.py sends apache-beam-<version>, and the Datastore helper sends beam-python-sdk/<version>. The S3 client is the odd one out.

This passes Config(user_agent_extra='apache-beam/%s' % beam_version.__version__) when constructing the client. botocore appends user_agent_extra to the end of the composed user agent, so the boto3, botocore, platform, and language segments are all preserved and only a suffix is added. The version comes from apache_beam.version.__version__, the same source gcsio.py uses. The practical benefit is that Beam's S3 traffic becomes identifiable in server access logs, which helps when diagnosing throttling or endpoint problems against Amazon S3 and against any other S3-compatible endpoint reached through --s3_endpoint_url.

Tests: a new ClientUserAgentTest in client_test.py constructs the client from a default S3Options() and asserts the composed client.client.meta.config.user_agent contains apache-beam/<version>. It is guarded with @unittest.skipIf(boto3_client is None, ...) following the pattern already used in s3filesystem_test.py, and client construction needs no credentials and no region, so it runs offline. yapf and ruff are clean on both files.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant